home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15472 < prev    next >
Encoding:
Text File  |  1996-08-05  |  815 b   |  32 lines

  1. Path: omni2.voicenet.com!not-for-mail
  2. From: jchris@voicenet.com (John L. Christopher)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Bletcherous kludge!
  5. Date: 5 Apr 1996 13:20:55 -0500
  6. Organization: Voicenet - Internet Access - (215)674-9290
  7. Message-ID: <4k3oa7$9e6@omni2.voicenet.com>
  8. NNTP-Posting-Host: omni2.voicenet.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. In response to the problem of converting a null terminated character
  12. array Buffer (defined within the class String) into a floating point
  13. number - 
  14.  
  15.  
  16. An appropriate and totally C++ solution might be
  17.  
  18. #include <strstream.h>
  19. .
  20. .
  21. double String::Number() {
  22.     double        val;
  23.     istrstream    ist(Buffer);
  24.  
  25.     ist >> val;
  26.     return val;
  27. }
  28.  
  29. This uses the string stream facility of the language to use memory
  30. buffers as i/o sources and sinks (similar to the sprintf function
  31. of C).
  32.